package git.bds.nyc.admin.controller.gx.audit;

import git.bds.nyc.admin.model.vo.AuditFarmerAuthenticationInfoVO;
import git.bds.nyc.admin.model.vo.AuditFarmerAuthenticationVO;
import git.bds.nyc.admin.service.audit.gx.authentication.AuditFarmerAuthenticationService;
import git.bds.nyc.page.PageParam;
import git.bds.nyc.page.PageResult;
import git.bds.nyc.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @author 成大事
 * @since 2023/6/9 14:42
 */
@Api(tags = "供销社 审核农户注册")
@Slf4j
@Validated
@RestController
@RequestMapping("/admin/audit/farmer/authentication")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class AuditFarmerAuthenticationController {

    private final AuditFarmerAuthenticationService auditFarmerAuthenticationService;


    /**
     * 按类型获取农民页面
     *
     * @param pageParam 页面参数
     * @param type      类型
     * @return {@link R}<{@link PageResult}<{@link AuditFarmerAuthenticationVO}>>
     */
    @ApiOperation("分页获取农户列表根据类型")
    @PostMapping("/getFarmerPageByType/{type}")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "type",value = "类型",required = true, dataTypeClass = Integer.class)
    )
    public R<PageResult<AuditFarmerAuthenticationVO>> getFarmerPageByType(
            @Validated @RequestBody PageParam pageParam,
            @PathVariable("type") int type
    ){
        return R.ok(auditFarmerAuthenticationService.getFarmerPageByType(pageParam,type));
    }


    /**
     * 通过id获取农民身份验证信息
     *
     * @param id 身份证
     * @return {@link R}<{@link AuditFarmerAuthenticationInfoVO}>
     */
    @ApiOperation("根据id获取农户认证信息详情")
    @PostMapping("/getFarmerAuthenticationInfoById/{id}")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "id",value = "农户认证的id",required = true, dataTypeClass = Long.class)
    )
    public R<AuditFarmerAuthenticationInfoVO> getFarmerAuthenticationInfoById(
            @PathVariable("id") Long id
    ){
        return R.ok(auditFarmerAuthenticationService.getFarmerAuthenticationInfoById(id));
    }


    /**
     * 用id审计农民身份验证
     *
     * @param id     身份证
     * @param status 地位
     * @return {@link R}<{@link Boolean}>
     */
    @ApiOperation("根据id对农户的认证进行审核")
    @PostMapping("/auditFarmerAuthenticationById/{id}/{status}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = "是否通过 -1: 不通过  1: 通过", required = true, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "id",value = "农户认证的id",required = true, dataTypeClass = Long.class)
    })
    public R<Boolean> auditFarmerAuthenticationById(
            @PathVariable("id") Long id,
            @PathVariable("status") int status
    ){
        return R.decide(auditFarmerAuthenticationService.auditFarmerAuthenticationById(id, status));
    }


}
